package stego.StegoCaller;

import java.io.File;
import java.util.ArrayList;
import stego.Drivers;

public class Caller_CookieJAR
{

    public static String strMyClassName = java/lang/Class.getName();
    public static File fleCookieJAR_SaveDirectory = null;
    public static File fleEmbed_CookieJAR = null;
    public static File fleExtract_CookieJAR = null;
    public static File fleEncrypt_CookieJAR = null;
    public static File fleDecrypt_CookieJAR = null;
    public static File fleUpload_CookieJAR = null;
    public static File fleDownload_CookieJAR = null;
    public static File fleReCompose_CookieJAR = null;
    public static File fleClassPATH = null;

    public Caller_CookieJAR(File outputDirectory, ArrayList embedJARs, ArrayList extractJARs, ArrayList encryptJARs, ArrayList decryptJARs, ArrayList uploadJARs, ArrayList downloadJARs, 
            ArrayList recompose)
    {
        try
        {
            if(embedJARs != null && embedJARs.size() > 0 || extractJARs != null && extractJARs.size() > 0 || encryptJARs != null && encryptJARs.size() > 0 || decryptJARs != null && decryptJARs.size() > 0 || uploadJARs != null && uploadJARs.size() > 0 || downloadJARs != null && downloadJARs.size() > 0 || recompose != null && recompose.size() > 0)
            {
                fleCookieJAR_SaveDirectory = initializeTopPackageFolder(outputDirectory, "Cookie_JAR", 0);
                if(fleCookieJAR_SaveDirectory != null && fleCookieJAR_SaveDirectory.exists() && fleCookieJAR_SaveDirectory.isDirectory())
                {
                    fleEmbed_CookieJAR = initializeTopPackageFolder(fleCookieJAR_SaveDirectory, "Embed", 0);
                    fleExtract_CookieJAR = initializeTopPackageFolder(fleCookieJAR_SaveDirectory, "Extraxt", 1);
                    fleEncrypt_CookieJAR = initializeTopPackageFolder(fleCookieJAR_SaveDirectory, "Encrypt", 2);
                    fleDecrypt_CookieJAR = initializeTopPackageFolder(fleCookieJAR_SaveDirectory, "Decrypt", 3);
                    fleUpload_CookieJAR = initializeTopPackageFolder(fleCookieJAR_SaveDirectory, "Upload", 4);
                    fleDownload_CookieJAR = initializeTopPackageFolder(fleCookieJAR_SaveDirectory, "Download", 5);
                    fleReCompose_CookieJAR = initializeTopPackageFolder(fleCookieJAR_SaveDirectory, "ReCompose", 6);
                }
                Drivers.copyFilesToDirectory(embedJARs, fleEmbed_CookieJAR);
                Drivers.copyFilesToDirectory(extractJARs, fleExtract_CookieJAR);
                Drivers.copyFilesToDirectory(encryptJARs, fleEncrypt_CookieJAR);
                Drivers.copyFilesToDirectory(decryptJARs, fleDecrypt_CookieJAR);
                Drivers.copyFilesToDirectory(uploadJARs, fleUpload_CookieJAR);
                Drivers.copyFilesToDirectory(downloadJARs, fleDownload_CookieJAR);
                Drivers.copyFilesToDirectory(recompose, fleReCompose_CookieJAR);
                Drivers.sop((new StringBuilder("Population of Cookie JAR complete: ")).append(fleCookieJAR_SaveDirectory).toString());
                fleClassPATH = Drivers.querySelectFile(true, "Please the javac compiler e.g. %programfiles%\\java\\jdk<#>bin", 0, false, false);
                if(fleClassPATH == null || !fleClassPATH.isFile() || !fleClassPATH.getCanonicalPath().contains("javac"))
                {
                    Drivers.jop_Message("Invalid file selected", "Unable to Continue");
                } else
                {
                    Drivers.sop((new StringBuilder("Good compiler file chosen: ")).append(fleClassPATH.getCanonicalPath()).toString());
                }
            } else
            {
                Drivers.jop_Error("No files were selected to package together!", "Empty Cookie JAR!!!");
            }
        }
        catch(Exception e)
        {
            Drivers.eop("Caller_CookieJAR constructor", strMyClassName, e, e.getLocalizedMessage(), true);
        }
    }

    public File initializeTopPackageFolder(File fleOutputDirectory, String cookieJAR_FolderName_ONLY, int tempIndexNum)
    {
        File fleTempDirectory;
        if(cookieJAR_FolderName_ONLY == null || cookieJAR_FolderName_ONLY.length() < 1)
        {
            cookieJAR_FolderName_ONLY = (new StringBuilder("temp_")).append(tempIndexNum).toString();
        }
        fleTempDirectory = null;
        if(fleOutputDirectory == null || !fleOutputDirectory.exists() || !fleOutputDirectory.isDirectory())
        {
            fleOutputDirectory = new File((new StringBuilder(".")).append(System.getProperty("file.separator")).toString());
        }
        if(fleOutputDirectory.getCanonicalFile().toString().endsWith(System.getProperty("file.separator")))
        {
            fleTempDirectory = new File((new StringBuilder()).append(fleOutputDirectory.getCanonicalFile()).append(cookieJAR_FolderName_ONLY).toString());
        } else
        {
            fleTempDirectory = new File((new StringBuilder()).append(fleOutputDirectory.getCanonicalFile()).append(System.getProperty("file.separator")).append(cookieJAR_FolderName_ONLY).toString());
        }
        if(!fleTempDirectory.exists())
        {
            fleTempDirectory.mkdir();
        }
        return fleTempDirectory;
        Exception e;
        e;
        Drivers.eop("initializePackageFolders", strMyClassName, e, e.getLocalizedMessage(), true);
        return null;
    }

}
